#include <osa.h>
#include <avr/io.h>
#include <stdio.h> 
#include <string.h> 

#include "disp.h"
#include "keyin.h"

#ifndef NULL
#define NULL 0
#endif

#define LED_DGA_PORT	PORTB
#define LED_DGA_DIR		DDRB
#define LED_DGA			PB1

#define LED_DGB_PORT	PORTC
#define LED_DGB_DIR		DDRC
#define LED_DGB			PC4

#define LED_DGC_PORT	PORTC
#define LED_DGC_DIR		DDRC
#define LED_DGC			PC1

#define LED_DGD_PORT	PORTB
#define LED_DGD_DIR		DDRB
#define LED_DGD			PB4

#define LED_DGE_PORT	PORTB
#define LED_DGE_DIR		DDRB
#define LED_DGE			PB5

#define LED_DGF_PORT	PORTC
#define LED_DGF_DIR		DDRC
#define LED_DGF			PC5

#define LED_DGG_PORT	PORTB
#define LED_DGG_DIR		DDRB
#define LED_DGG			PB3

#define LED_DGH_PORT	PORTC
#define LED_DGH_DIR		DDRC
#define LED_DGH			PC0

//****************************************//
#define LED_PD0_PORT	PORTC
#define LED_PD0_DIR		DDRC
#define LED_PD0			PC2

#define LED_PD1_PORT	PORTC
#define LED_PD1_DIR		DDRC
#define LED_PD1			PC3

#define LED_PD2_PORT	PORTB
#define LED_PD2_DIR		DDRB
#define LED_PD2			PB0

#define LED_PD3_PORT	PORTB
#define LED_PD3_DIR		DDRB
#define LED_PD3			PB2

#define LED_PD4_PORT	PORTD
#define LED_PD4_DIR		DDRD
#define LED_PD4			PD7


//#define DISP_TIME_INIT 		(10 ms)
#define DISP_TIME_INIT 		(5 ms)
//#define DISP_TIME_INIT 		(1.5 ms)
//#define DISP_TIME_INIT 		(1 ms)

#define MSG_DISPLAY_MAX 10
OST_QUEUE   queue_display;
OST_MSG   	msg_display_queue[MSG_DISPLAY_MAX];
OST_MSG 	msg_display_t;

enum ENUM_BLINKS 
{
	SEGMENT_BLINK_OFF,
	SEGMENT_BLINK_ON
};

/*
   -- a -- 
   f     b
   -- g --
   e     c
   -- d -- h
*/

const unsigned char display_digi_map_t[] = 
{
   /* hgfedcba */
    0b00111111,	/*0*/
	0b00000110,	/*1*/
    0b01011011,	/*2*/
    0b01001111, /*3*/
    0b01100110, /*4*/
    0b01101101, /*5*/
    0b01111101, /*6*/
    0b00000111, /*7*/
    0b01111111, /*8*/
    0b01101111, /*9*/
    0b00000000,  /*all off,10*/
	0b11111111,  /*all on,11*/	
	0b10000000, /*.,12*/
	0b00000001, /*_,13*/
	0b00000010, /*-,14*/
	0b00000011, /*:,15*/
	0b00000100, /*',16*/
	0b01000000, /*-,17*/
	0b01010100, /*n,18*/
	0b01110001, /*f,19*/
	0b01011110, /*d,20*/
	0b00111001, /*c,21*/
	0b00011100, /*u,22*/
	0b01010000, /*r,23*/
	0b00000000 /*Null,24*/	
};

struct
{
	char curr_pos;
	unsigned char toggle_time_on;
	unsigned char toggle_time_off;
	char toggle_flg;
	char output_port;
	char segment[SEGMENT_DIGIT_MAX];
}
disp_process;

struct
{
	char update;
	char motion_flg;
	char time_update;
	char opt_flg;
	char output_port;
	char output_port_bak;
	char post[SEGMENT_DIGIT_MAX];
}
disp_raw_data;

struct
{
	char time_update;
	signed int time_disp;
	char curr_post;
	char opt_flg;
	char post[SEGMENT_DIGIT_MAX];
}
disp_motion_data;


/********************************************************************************
 *                                                                              *
 *  TASK:           EnableLedDigit                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void EnableLEDDigit( void )
{
	LED_DGA_DIR |= _BV(LED_DGA);
	LED_DGB_DIR |= _BV(LED_DGB);
	LED_DGC_DIR |= _BV(LED_DGC);
	LED_DGD_DIR |= _BV(LED_DGD);
	LED_DGE_DIR |= _BV(LED_DGE);
	LED_DGF_DIR |= _BV(LED_DGF);
	LED_DGG_DIR |= _BV(LED_DGG);
	LED_DGH_DIR |= _BV(LED_DGH);

}


/********************************************************************************
 *                                                                              *
 *  TASK:           DisableLedDigit                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void DisableLEDDigit( void )
{
	LED_DGA_DIR &= ~_BV(LED_DGA);
	LED_DGB_DIR &= ~_BV(LED_DGB);
	LED_DGC_DIR &= ~_BV(LED_DGC);
	LED_DGD_DIR &= ~_BV(LED_DGD);
	LED_DGE_DIR &= ~_BV(LED_DGE);
	LED_DGF_DIR &= ~_BV(LED_DGF);
	LED_DGG_DIR &= ~_BV(LED_DGG);
	LED_DGH_DIR &= ~_BV(LED_DGH);
	
}

/********************************************************************************
 *                                                                              *
 *  TASK:           SetLEDDigitOutput                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void SetLEDDigitOutput(char p_digit)
{
	if( p_digit &  _BV(0) )
		LED_DGA_PORT &= ~_BV(LED_DGA);
	else
		LED_DGA_PORT |= _BV(LED_DGA);
	
	if( p_digit & _BV(1) )
		LED_DGB_PORT &= ~_BV(LED_DGB);
	else
		LED_DGB_PORT |= _BV(LED_DGB);
		
	if( p_digit & _BV(2) )
		LED_DGC_PORT &= ~_BV(LED_DGC);
	else
		LED_DGC_PORT |= _BV(LED_DGC);
		
	if( p_digit & _BV(3) )
		LED_DGD_PORT &= ~_BV(LED_DGD);
	else
		LED_DGD_PORT |= _BV(LED_DGD);
		
	if( p_digit & _BV(4) )
		LED_DGE_PORT &= ~_BV(LED_DGE);
	else
		LED_DGE_PORT |= _BV(LED_DGE);
		
	if( p_digit & _BV(5) )
		LED_DGF_PORT &= ~_BV(LED_DGF);
	else
		LED_DGF_PORT |= _BV(LED_DGF);
		
	if( p_digit & _BV(6) )
		LED_DGG_PORT &= ~_BV(LED_DGG);
	else
		LED_DGG_PORT |= _BV(LED_DGG);

	if( p_digit & _BV(7) )
		LED_DGH_PORT &= ~_BV(LED_DGH);
	else
		LED_DGH_PORT |= _BV(LED_DGH);
		
}

/********************************************************************************
 *                                                                              *
 *  TASK:           SetLEDDisplayPortOutput                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void SetLEDDisplayPortOutput(char output)
{
	if(output == TRUE)
		LED_DGC_PORT &= ~_BV(LED_DGC);
	else
		LED_DGC_PORT |= _BV(LED_DGC);
}

/********************************************************************************
 *                                                                              *
 *  TASK:           InitLEDPostOut                                              * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void InitLEDPostOut(void)
{
	LED_PD0_DIR |= _BV(LED_PD0);
	LED_PD1_DIR |= _BV(LED_PD1);
	LED_PD2_DIR |= _BV(LED_PD2);
	LED_PD3_DIR |= _BV(LED_PD3);
	LED_PD4_DIR |= _BV(LED_PD4);
	
}

/********************************************************************************
 *                                                                              *
 *  TASK:           InitLEDPostOut                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void SetAllLEDPostOff(void)
{
	LED_PD0_PORT &= ~_BV(LED_PD0);
	LED_PD1_PORT &= ~_BV(LED_PD1);
	LED_PD2_PORT &= ~_BV(LED_PD2);
	LED_PD3_PORT &= ~_BV(LED_PD3);
	LED_PD4_PORT &= ~_BV(LED_PD4);
	
}

/********************************************************************************
 *                                                                              *
 *  TASK:           LEDPostOut                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void SetLEDPostOn(char post )
{
	//SetAllLEDPostOff();
	
	switch(post)
	{
		case 0:
			LED_PD0_PORT |= _BV(LED_PD0);
			break;	
		case 1:
			LED_PD1_PORT |= _BV(LED_PD1);
			break;
		case 2:
			LED_PD2_PORT |= _BV(LED_PD2);
			break;
		case 3:
			LED_PD3_PORT |= _BV(LED_PD3);
			break;
		case 4:
			LED_PD4_PORT |= _BV(LED_PD4);
			break;
		default:
			break;
	}

}

/********************************************************************************
 *                                                                              *
 *  TASK:           DispFlushMsgBuff                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
#define DISP_MSG_BUFF_MAX 5
unsigned char DispMsgBuffIn = 0;
unsigned char DispMsgBuffOut = 0;
ST_DISP_MSG DispMsgBuff[DISP_MSG_BUFF_MAX];
void DispFlushMsgBuff(void)
{
	DispMsgBuffIn = 0;
	DispMsgBuffOut = 0;	
}


/********************************************************************************
 *                                                                              *
 *  TASK:           InitDispMsgBuff                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void InitDispMsgBuff( void )
{
	DispFlushMsgBuff();
	
	//printf("sizeof(DispMsgBuff)=%d",sizeof(DispMsgBuff));	
	memset((void *)((char *)&DispMsgBuff),0x00,sizeof(DispMsgBuff));
	
}

/********************************************************************************
 *                                                                              *
 *  TASK:           DispPutMsgBuff                                              * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
int DispIsMsgBuffEmpty(void)
{
	if( DispMsgBuffIn == DispMsgBuffOut )
	{
		return TRUE;
	}
	return FALSE;	
}

/********************************************************************************
 *                                                                              *
 *  TASK:           DispPutMsgBuff                                              * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
int DispPutMsgBuff(ST_DISP_MSG *msg)
{
	unsigned char in = DispMsgBuffIn + 1;
	
	if (in >= DISP_MSG_BUFF_MAX)
		in = 0;
		
	if (in == DispMsgBuffOut)	// isFull()
	{
		return FALSE;
	}

	// printf("%02X %X %X ",msg->act,msg->opt_flg,msg->time_update);	
	// printf("%X %X %X %X %X\r\n",msg->post[0],msg->post[1],msg->post[2],msg->post[3],msg->post[4]);	

	
	memcpy((void *)&DispMsgBuff[DispMsgBuffIn],(void *)msg,sizeof(ST_DISP_MSG));
	DispMsgBuffIn = in;
	
	return TRUE;
}


/********************************************************************************
 *                                                                              *
 *  TASK:           DispPopMsgBuff                                              * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
ST_DISP_MSG * DispPopMsgBuff(void)
{
	ST_DISP_MSG * p_msg;
	unsigned char out;
		
	if( DispMsgBuffIn == DispMsgBuffOut )
		return (ST_DISP_MSG *)NULL;
	
	p_msg = &DispMsgBuff[DispMsgBuffOut];
	
	out = DispMsgBuffOut+1;
	if (out >= DISP_MSG_BUFF_MAX)
		out = 0;
		
	DispMsgBuffOut = out;			
	
	return p_msg;

}


/********************************************************************************
 *                                                                              *
 *  TASK:           DisplaySetToggleTime                                        * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
  //#define DISP_TOGGLE_TIME 1500 ms
  #define DISP_TOGGLE_TIME 1000 ms
 int DisplaySetToggleTime(char on_off_mode, char toggle_mode)
 {
	int toggle_time;
	switch(toggle_mode)
	{
		default:
		case 0:
				if(on_off_mode == 0) //ON
					toggle_time =  ((DISP_TOGGLE_TIME / DISP_TIME_INIT) * 8)/10;
				else
					toggle_time =  ((DISP_TOGGLE_TIME / DISP_TIME_INIT) * 2)/10;
			break;
		case 1:
				if(on_off_mode == 0) //ON
					toggle_time =  ((DISP_TOGGLE_TIME / DISP_TIME_INIT) * 2)/10;
				else
					toggle_time =  ((DISP_TOGGLE_TIME / DISP_TIME_INIT) * 8)/10;
			break;
		case 2:
				if(on_off_mode == 0) //ON
					toggle_time =  ((DISP_TOGGLE_TIME / DISP_TIME_INIT) * 5)/10;
				else
					toggle_time =  ((DISP_TOGGLE_TIME / DISP_TIME_INIT) * 5)/10;
			break;			
		// case 3:
				// toggle_time =  5000 ms / DISP_TIME_INIT;
			// break;			
	}
	return toggle_time;
 }
 

/********************************************************************************
 *                                                                              *
 *  TASK:           InitDisp                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void InitDisp( void )
{
	//Init LED Post
	InitLEDPostOut();

	//Init LED Digit ports
	DisableLEDDigit();
	SetLEDDigitOutput(0x00);
		
	//Init LED Digit ports
	SetAllLEDPostOff();
	
	//Init Msg buff
	InitDispMsgBuff();
	
	disp_process.curr_pos = 0;
	disp_process.toggle_flg = 0x00;
	disp_process.output_port = FALSE;
	disp_process.toggle_time_on = DisplaySetToggleTime(0,0);
	disp_process.toggle_time_off = DisplaySetToggleTime(1,0);

	memset((void *)&disp_process.segment[0]
				, display_digi_map_t[SEGMENT_ALL_OFF]
				, SEGMENT_DIGIT_MAX);
				
	disp_raw_data.update 		= FALSE;
	disp_raw_data.motion_flg 	= FALSE;
	disp_raw_data.time_update 	= 0 ms;
	disp_raw_data.opt_flg		= 0x00;
	disp_raw_data.output_port	= FALSE;
	disp_raw_data.output_port_bak	= FALSE;
	
	memset((void *)&disp_raw_data.post[0]
				, SEGMENT_ALL_OFF
				, SEGMENT_DIGIT_MAX);	
			
	 OS_Queue_Create(queue_display, msg_display_queue, MSG_DISPLAY_MAX);  
				
}

/********************************************************************************
 *                                                                              *
 *  TASK:           DisplayUpdate                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
 void DisplayUpdate(void)
 {
	static unsigned int segment_toggle_interval = 0;
	static unsigned char segment_toggle_mode 	 = SEGMENT_BLINK_ON;
	
	char curr_post = disp_process.curr_pos;
	char post;
	
	segment_toggle_interval++;
	if(segment_toggle_mode == SEGMENT_BLINK_ON)
	{
		if(segment_toggle_interval > disp_process.toggle_time_on)
		{
			segment_toggle_mode = SEGMENT_BLINK_OFF;
			segment_toggle_interval = 0;
		}
	}
	else
	{
		if(segment_toggle_interval > disp_process.toggle_time_off)
		{
			segment_toggle_mode = SEGMENT_BLINK_ON;
			segment_toggle_interval = 0;
		}	
	}	
	
	SetAllLEDPostOff();	
	
	if( ((disp_process.toggle_flg & (0x01 << curr_post))  != 0 ) && segment_toggle_mode == SEGMENT_BLINK_OFF )
		SetLEDDigitOutput( display_digi_map_t[SEGMENT_ALL_OFF] );	
	else
		SetLEDDigitOutput( disp_process.segment[(int)curr_post] );
	
	if(curr_post == 4)
	{
		SetLEDDisplayPortOutput( disp_process.output_port );
	}
	
	SetLEDPostOn( curr_post );	
	
	if( ++curr_post >= SEGMENT_DIGIT_MAX )
	{
		 curr_post = 0;
		 
		if(disp_raw_data.update == TRUE)
		{
			for(post=0;post<SEGMENT_DIGIT_MAX;post++)
			{
				disp_process.segment[(int)post] = display_digi_map_t[(int)disp_raw_data.post[(int)post]];
			}
			disp_process.toggle_flg = disp_raw_data.opt_flg & 0b00011111;
			disp_process.toggle_time_on = DisplaySetToggleTime(0, (disp_raw_data.opt_flg & 0b01100000) >> 5 );
			disp_process.toggle_time_off = DisplaySetToggleTime(1, (disp_raw_data.opt_flg & 0b01100000) >> 5 );
			// disp_process.output_port = !!(disp_raw_data.opt_flg & 0b10000000);
			disp_process.output_port = disp_raw_data.output_port;
			disp_raw_data.update = FALSE;
				
		}
	}
	disp_process.curr_pos = curr_post;
 }

 
 /********************************************************************************
 *                                                                              *
 *  TASK:           DisplayMsgManage                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void DisplayMsgManage (void)
{
	ST_DISP_MSG * msg_ptr;
	
	if ( OS_Queue_Check(queue_display) )      // If any message present
	{
		OS_Queue_Accept(queue_display, msg_display_t);  // then accept it
		msg_ptr = (ST_DISP_MSG *)msg_display_t;
		
		if((msg_ptr->act & CLEAR_DISPLAY) != 0)
		{		
			DispFlushMsgBuff();
			disp_raw_data.time_update = 0;
			disp_raw_data.motion_flg = FALSE;
		}		
		DispPutMsgBuff( msg_ptr );
	}	
	
}



 /********************************************************************************
 *                                                                              *
 *  TASK:           DisplayMsgManage                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void DisplayMsgProcess (void)
{
	ST_DISP_MSG * msg_ptr;
	
		
	if( disp_raw_data.time_update > 0 )
	{
		disp_raw_data.time_update--;
	}
	else 
	{
		if( DispIsMsgBuffEmpty() == FALSE && disp_raw_data.update == FALSE && disp_raw_data.motion_flg == FALSE)
		{
			msg_ptr = DispPopMsgBuff();			
			if((msg_ptr->act & ~CLEAR_DISPLAY) == NORMAL_DISPLAY)
			{
				memcpy((void *)&disp_raw_data.post[0], (const void *)msg_ptr->post, SEGMENT_DIGIT_MAX);
				disp_raw_data.opt_flg = msg_ptr->opt_flg;
				disp_raw_data.time_update = msg_ptr->time_update;		//time for display
				disp_raw_data.output_port = disp_raw_data.output_port_bak;		
				disp_raw_data.update = TRUE;
			}
			else if((msg_ptr->act & ~CLEAR_DISPLAY) == MOTION_DISPLAY)
			{
				memcpy((void *)&disp_motion_data.post[0], (const void *)msg_ptr->post, SEGMENT_DIGIT_MAX);
				disp_motion_data.time_update = msg_ptr->time_update;		//time for display
				disp_motion_data.opt_flg = msg_ptr->opt_flg;
				disp_motion_data.time_disp = 0;
				disp_motion_data.curr_post = 0xFF;
				disp_raw_data.motion_flg = TRUE;
			}
			else if((msg_ptr->act & ~CLEAR_DISPLAY) == PORT_OUT_DISPLAY)
			{
				disp_raw_data.output_port = !!msg_ptr->opt_flg;
				disp_raw_data.output_port_bak = !!msg_ptr->opt_flg;
				disp_raw_data.update = TRUE;
			}			
		}
	}
}

 /********************************************************************************
 *                                                                              *
 *  TASK:           DispMotionProcess                                           * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
#define DISP_MOTION_TIME 13
 void DispMotionProcess(void)
{
	unsigned char ucCount;
	unsigned char ucMotionPos;
	
	if(disp_raw_data.motion_flg == TRUE && disp_raw_data.update == FALSE) 
	{	
		disp_motion_data.time_disp--;
		if(disp_motion_data.time_disp <= 0)
		{
			disp_motion_data.time_disp = DISP_MOTION_TIME;
			if( disp_motion_data.curr_post == 0xFE)
			{
				disp_raw_data.motion_flg = FALSE;
				disp_motion_data.curr_post = 0xFF;		
			}		
			else if( disp_motion_data.curr_post == 0xFF)
			{			
				memset((void *)&disp_raw_data.post[0], SEGMENT_ALL_OFF, SEGMENT_DIGIT_MAX);
				disp_raw_data.opt_flg = 0;
				disp_raw_data.time_update = 0;
				disp_raw_data.output_port = FALSE;
				disp_motion_data.curr_post = 0;
				disp_raw_data.update = TRUE;
			}
			else if( disp_motion_data.curr_post < (SEGMENT_DIGIT_MAX-1) )
			{			
				ucMotionPos = 0;
				for( ucCount=0; ucCount<(SEGMENT_DIGIT_MAX-1); ucCount++ )
				{
					// disp_motion_data.curr_post = 0
					// ucCount 		= 0,1,2,3
					// disp_motion_data.post	= x,x,x,0

					// disp_motion_data.curr_post = 1
					// ucCount 		= 0,1,2,3
					// disp_motion_data.post	= x,x,0,1
									
					// disp_motion_data.curr_post = 2
					// ucCount 		= 0,1,2,3
					// disp_motion_data.post	= x,0,1,2

					// disp_motion_data.curr_post = 3
					// ucCount 		= 0,1,2,3
					// disp_motion_data.post	= 0,1,2,3
									
					if( ucCount < ((SEGMENT_DIGIT_MAX-2) - disp_motion_data.curr_post) )
					{
						disp_raw_data.post[ucCount] = SEGMENT_ALL_OFF;						
					}
					else
					{
						disp_raw_data.post[ucCount] = disp_motion_data.post[ucMotionPos];
						ucMotionPos++;
					}																						
				}		
				disp_raw_data.time_update = 0;		//time for display				
				disp_motion_data.curr_post++;
				disp_raw_data.update = TRUE;				
			}
			else
			{
				disp_motion_data.curr_post = 0xFE;
				disp_raw_data.post[SEGMENT_DIGIT_MAX-1] = disp_motion_data.post[SEGMENT_DIGIT_MAX-1];
				disp_raw_data.time_update = disp_motion_data.time_update;		//time for display		
				disp_raw_data.opt_flg = disp_motion_data.opt_flg;
				//disp_raw_data.output_port = disp_motion_data.output_port;
				disp_raw_data.update = TRUE;
			}
		}
	}
}

 /********************************************************************************
 *                                                                              *
 *  TASK:           TaskDisp                                                   * 
 *                                                                              *
 *------------------------------------------------------------------------------*
 *
 *  description:    
 *
 ********************************************************************************/
void TaskDisp (void)
{	
	// printf("TaskDisp\r\n");
	static unsigned char disp_time_interval = 0;
	
	disp_raw_data.update = TRUE;
	disp_raw_data.opt_flg = 0b00000000;
	memset((void *)&disp_raw_data.post[0]
				, SEGMENT_ALL_ON
				, SEGMENT_DIGIT_MAX);
	
	EnableLEDDigit();
	
    for (;;)
    {	
		OS_Delay( DISP_TIME_INIT );		
			
		DisplayUpdate();
		
		DispMotionProcess();
		
		if(disp_time_interval == 0)
		{
			DisplayMsgManage();
		
			DisplayMsgProcess();
			
			disp_time_interval = 5;
		}
		else
		{
			disp_time_interval--;
		}
	}
}
